//
//  TodayViewController.m
//  TodayExtensionWidigit
//
//  Created by windCould on 17/1/11.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "TodayViewController.h"
#import "BKWidigitView.h"
#import <NotificationCenter/NotificationCenter.h>

#define kWidth self.view.frame.size.width
#define kHeight self.view.frame.size.height

@interface TodayViewController () <NCWidgetProviding,BKWidigitViewDelegate>

@property (nonatomic, strong) BKWidigitView *widgetHeaderView;

@end

@implementation TodayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpViews];
    
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    if ([[UIDevice currentDevice].systemVersion doubleValue] >= 10.0) {
        self.extensionContext.widgetLargestAvailableDisplayMode = NCWidgetDisplayModeCompact;
    }else {
        self.preferredContentSize = CGSizeMake(kWidth, 100);
    }
}

#pragma mark ----------界面初始化------------

- (void)setUpViews {
    
    self.widgetHeaderView = [[BKWidigitView alloc] initWithFrame:self.view.frame];
    self.widgetHeaderView.myDelegate = self;
    [self.view addSubview:self.widgetHeaderView];
}

#pragma mark --------NCWidgetProviding代理方法------------

- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
    
    //    NCUpdateResultNewData   新的内容需要重新绘制视图
    //    NCUpdateResultNoData    部件不需要更新
    //    NCUpdateResultFailed    更新过程中发生错误
    completionHandler(NCUpdateResultNoData);
}

- (UIEdgeInsets)widgetMarginInsetsForProposedMarginInsets:(UIEdgeInsets)defaultMarginInsets{
    
    return UIEdgeInsetsMake(0, 8, 0, 8);
}



#pragma mark ----------WidgetDelegate代理方法-----------

- (void)clickWidigitFunctionBtnWithIndex:(NSInteger)index {
    
    [self.extensionContext openURL:[NSURL URLWithString:[NSString stringWithFormat:@"medicalWidgets://%ld",index]] completionHandler:^(BOOL success) {
        
    }];
}

@end
